<template>
  <AnalysisWrap titleText="限高分析" @goAnalysisOtherViewFn="goAnalysisOtherView">
    <template #container>
      <div class="header">
        <div class="header-text">
          <span class="number">{{ sliderLimit }}</span
          ><span class="unit">米</span>
        </div>
        <span class="into">当前限制高度</span>
      </div>
      <div class="control">
        <span class="lable">地表海拔：</span>
        <mars-input class="point-input" v-model:value="bottomHeight"></mars-input>
        <mars-button class="point-btn" @click="onMapClickPoint">图上选点</mars-button>
      </div>
      <div class="control">
        <span class="lable">限制高度：</span>
        <mars-slider @change="onChangeLimitHeight" v-model:value="sliderLimit" :min="0" :max="180" :step="0.1" />
      </div>
      <div class="control-play">
        <mars-button class="btn" @click="onDrawModelLimitExtent">绘制矩形</mars-button>
        <mars-button class="btn" @click="onDrawModelLimitPloy">绘制面</mars-button>
        <mars-button class="btn" danger @click="removeModelLimitData">清除</mars-button>
      </div>
    </template>
  </AnalysisWrap>
</template>

<script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue"
import AnalysisWrap from "./analysis-wrap.vue"
import * as mapWork from "./map"

const emit = defineEmits(["goAnalysisOtherView"])

function goAnalysisOtherView(name: string) {
  emit("goAnalysisOtherView", name)
}

onMounted(() => {
  mapWork.onMountedModelLimit()
})
onUnmounted(() => {
  mapWork.onUnmountedModelLimit()
})

const removeModelLimitData = () => {
  mapWork.removeModelLimitData()
}

// 地表高度
const bottomHeight = ref<number>(0)
const onMapClickPoint = () => {
  mapWork.onMapClickPoint().then((e) => {
    bottomHeight.value = e
  })
}

// 绘制矩形
const onDrawModelLimitExtent = () => {
  mapWork.onDrawModelLimitExtent()
}
// 绘制矩形
const onDrawModelLimitPloy = () => {
  mapWork.onDrawModelLimitPloy()
}

// 限制高度 滑动条
const sliderLimit = ref<number>(80)
const onChangeLimitHeight = () => {
  mapWork.onChangeLimitHeight(sliderLimit.value)
}
</script>
<style scoped lang="less">
.f-pt {
  margin-top: 10px;
}
.ant-slider {
  flex: 1;
}
.limit-mb {
  margin-bottom: 20px;
}
.header {
  text-align: center;
  margin: 54px 0 40px 0;
  .header-text {
    color: #3385ff;
    margin-bottom: 13px;
    .number {
      color: #3385ff;
      text-shadow: 0px 6px 30px rgba(51, 133, 255, 0.7);
      font-size: 32px;
      font-weight: bold;
    }
    .unit {
      display: inline-block;
      margin-left: 5px;
      font-weight: 400;
      font-size: 14;
    }
  }
  .into {
    color: rgba(234, 242, 255, 0.6);
    font-size: 14px;
  }
}

.control {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  .lable {
    width: 70px;
    font-size: 14px;
    text-align: center;
    color: rgba(234, 242, 255, 0.8);
  }
  .point-input {
    flex: 1;
  }
  .point-btn {
    width: 90px;
    background-color: rgba(51, 133, 255, 0.8);
    margin-left: 8px;
  }

  .checkModelText {
    color: rgba(234, 242, 255, 0.6);
  }
}

.control-play {
  display: flex;
  .btn {
    flex: 1;
    &:nth-child(n + 2) {
      margin-left: 4px;
    }
  }
}
</style>
